package Tesk83;

import java.util.Scanner;

public class test1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串: ");
        String input = scanner.nextLine();

        System.out.println(reverse(input));
    }

    public static String reverse(String input) {
        // 此处编写算法实现
        //判断字符串是否为null或为""
        if (input == null || input.isEmpty()){
            return "不能输入空值";
        }

        //创建StringBuffer对象
        StringBuffer sb = new StringBuffer();
        for (int i = input.length() - 1; i >= 0 ; i--) {//倒着循环获取每一个字符
            //拼接到StringBuffer上
            sb.append(input.charAt(i));
        }
        //返回
        return sb.toString();
    }
}
